package view;

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

import control.MainListener;
import control.util.Util;

@SuppressWarnings("serial")
public class MainGUI extends JFrame {

	private JPanel mainPanel;
	private JSplitPane splitPane;
	
	private IpGUI ipGUI;
	private TreeGUI treeGUI;
	private InfoGUI infoGUI;
	private MainListener mainListener;
	
	public MainGUI() {
		initObjs();
		initProperties();
	}
	
	private void initObjs() {
		mainPanel = new JPanel(new FlowLayout());
		
		splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
		
		ipGUI = new IpGUI();
		treeGUI = new TreeGUI();
		infoGUI = new InfoGUI(Util.MAIN_PANEL_WIDTH-Util.TREE_PANEL_WIDTH, Util.MAIN_PANEL_HEIGHT-Util.IP_PANEL_HEIGHT);
		
		mainListener = new MainListener(ipGUI, treeGUI, infoGUI);
	}
	
	private void initProperties() {
		splitPane.setLeftComponent(treeGUI);
		splitPane.setRightComponent(infoGUI);
		
		ipGUI.addListeners(mainListener);
		treeGUI.addListeners(mainListener);
		infoGUI.addListeners(mainListener);
		
		mainPanel.setBackground(Util.COLOR_BACKGROUND);
		mainPanel.setPreferredSize(new Dimension(Util.MAIN_PANEL_WIDTH + 50, Util.MAIN_PANEL_HEIGHT + 80));
		mainPanel.add(ipGUI);
		mainPanel.add(splitPane);
		
		add(mainPanel);
		
		pack();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		setVisible(true);
	}
	
	public static void main(String[] args) {
		new MainGUI();
	}
}
